<?php
/** 
 * @package ShareThisBar Plugin for Joomla! 1.5
 * @subpackage Form Element Stbjscss
 * @version $Id: sharethisbar.php 3.5 2012-12-29 17:00:33Z Dusanka $
 * @author Dusanka Ilic
 * @copyright (C) 2012 - Dusanka Ilic, All rights reserved.
 * @authorEmail: gog27.mail@gmail.com
 * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html, see LICENSE.txt
**/

defined('JPATH_BASE') or die();
 
/**
 * Inserts css and javascript code into plugin manager form for ShareThisBar plugin.
 *
 * @package     ShareThisBar
 * @since       3.5
 */
class JElementStbjscss extends JElement {
 
        var $_name = 'Stbjscss';
 
        function fetchElement($name, $value, &$node, $control_name) {
	
		$doc = & JFactory::getDocument();
                
                $css = "
                   div.stbspace {
                       color:#1669b6!important; 
                       font-size:1.2em;
                       margin: 5px 0 0 0;
                    }
                    hr.stbhr {
                       border:1px solid #ca7916;
                       margin: 0 0 10px 0;
                    }
                ";
             
                $doc->addStyleDeclaration($css);
                
                $jsAdminCode = "<!--//--><![CDATA[//><!--  
                        window.addEvent('domready', function() {
                            
                            // language ---------------------------------
                            
                            var langmode = false;
                            var langmode1 = document.id('paramslangmode1');  
                            if (langmode1) {
                               if (langmode1.checked) {
                                  langmode = true;
                               }
                            } 
                            
                            // za J15
                            //console.log('langmode je: '+langmode.value);
                            //console.log('langmode je: '+langmode.checked);
                            
                            document.id('paramslangmode0').addEvent('click',function(myevent) {
                              // extend the event with MooTools, we may stop the event
                              //var e = new Event(myevent);
                              //e.stop();
                  
                              var langcode=document.id('paramslangcode'); 
                              langcode.disabled='';  
                            });
                            
                            document.id('paramslangmode1').addEvent('click',function(myevent) {
                             var langcode=document.id('paramslangcode'); 
                             langcode.disabled='true';
                            });
                               
                            // Kontrola za izbor jezika 
                            var langcode = document.id('paramslangcode');
                            
                            if (langcode) {
                            // Ako je automatski izbor jezika disable-uj ovu kontrolu za izbor jezika.   
                            if (langmode == 1) {
                              langcode.disabled='true';
                            } else {
                              langcode.disabled='';
                            }
                            }
                            
                            // spreadword  ---------------------------------    
                            
                            var spreadword = false;
                            var spreadword1 = document.id('paramsspreadword1');  
                            if (spreadword1) {
                               if (spreadword1.checked) {
                                 spreadword = true;
                               }
                            } 

                            document.id('paramsspreadword0').addEvent('click',function(ev) {
                             var spreadwordpic=document.id('paramsspreadwordpic'); 
                             spreadwordpic.disabled='true';
                            });

                           document.id('paramsspreadword1').addEvent('click',function(ev) {
                             var spreadwordpic=document.id('paramsspreadwordpic'); 
                             spreadwordpic.disabled='';
                            });
    
                            var spreadwordpic = document.id('paramsspreadwordpic');
                            
                            if (spreadwordpic) {
                            if (spreadword == 1) {
                              spreadwordpic.disabled='';
                            } else {
                              spreadwordpic.disabled='true';
                            }                             
                            }
                            
                            // stbchoosestyle i btnstyle ---------------------------------    
                            
                            var arrStbChooseStyle = document.getElementsByName('params[stbchoosestyle]');
                            //console.log(arrStbChooseStyle);

                            var txtbtnstyle=document.id('paramsbtnstyle');  
                            for (var i = 0; i < arrStbChooseStyle.length; i++ )
                            {
                                //var result = arrStbChooseStyle[i];
                                //console.log(result);
                                
                                // Ovo treba pri otvaranju strane za border oko slike stila.    
                                if (arrStbChooseStyle[i].checked) {
                                  $$('label div.btnstyleimg img').setStyle('border','none');
                                  $$('label[for='+arrStbChooseStyle[i].id+'] div.btnstyleimg img').setStyle('border','1px solid orange');

                                }

                                arrStbChooseStyle[i].addEvent('click',function() {
                                   
                                  console.log(' this '+this.value);
                                  txtbtnstyle.value=this.value;
                                  
                                  // Ovo treba za border oko slike stila.    
                                  $$('label div.btnstyleimg img').setStyle('border','none');
                                  $$('label[for='+this.id+'] div.btnstyleimg img').setStyle('border','1px solid orange');

                                    
                                });

                            }
                                                        
                            document.id('paramscb1_code').addEvent('change',function(ev) { 
                                                         
                             console.log(' pre paramscb1_code this value '+this.value);   
                          
                             
                             if (!this.value) return this; // Don't alter the empty string  
                             // Umesto jedne obrnute crte morao sam \\
                             var cc = this.value.replace(/[\\r\\n]/g, ''); // Regular expression magic   
                             this.value = cc;
                             
                             
                             console.log(' posle paramscb1_code this value '+this.value);  

                            }); 
                            
                            document.id('paramscb2_code').addEvent('change',function(ev) { 
                                                                                
                             if (!this.value) return this; 
                             // Umesto jedne obrnute crte morao sam \\
                             var cc = this.value.replace(/[\\r\\n]/g, ''); 
                             this.value = cc;
                             
                            }); 
                            
                            document.id('paramscb3_code').addEvent('change',function(ev) { 
                                                                                
                             if (!this.value) return this; 
                             // Umesto jedne obrnute crte morao sam \\
                             var cc = this.value.replace(/[\\r\\n]/g, ''); 
                             this.value = cc;
                             
                            }); 
                            
                                                  
                        }); 

                       //--><!]]> ";
                
                $doc->addScriptDeclaration($jsAdminCode);
           
		return;
              
	}
        // Dont show label.
        function fetchTooltip($label, $description, &$xmlElement, $control_name='', $name='') {
		return false;
	}
        
}